package com.yihusitian.zsxq.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yihusitian.zsxq.pojo.data.UserDO;
import com.yihusitian.zsxq.pojo.dto.Talk;
import com.yihusitian.zsxq.service.IDGenerator;
import com.yihusitian.zsxq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yihusitian.zsxq.service.TalkService;
import com.yihusitian.zsxq.pojo.data.TalkDO;
import com.yihusitian.zsxq.mapper.TalkMapper;

/**
 * @Description TODO
 * @Author LeeHo
 * @Date 2021-03-25 11:49:28
 */
@Service
public class TalkServiceImpl extends ServiceImpl<TalkMapper, TalkDO> implements TalkService {

    @Autowired
    private UserService userService;

    @Override
    public TalkDO createTalk(Talk talk) {
        if (talk == null) {
            return null;
        }
        UserDO userDO = userService.createOrUpdate(talk.getOwner());
        TalkDO talkDO = TalkDO.builder().id(IDGenerator.generateId()).ownerId(userDO.getId()).text(StrUtil.emptyToDefault(talk.getText(), StrUtil.EMPTY)).build();
        talkDO.insert();
        return talkDO;
    }
}